<?php

namespace App\Models\SettingManagement;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Status extends Model{
    use HasFactory,SoftDeletes;

    protected $table = "setting_mgt__statuses";
    const FK_ID = "status_code";
    protected $guarded = [];
    protected $keyType = "string";
    protected $primaryKey = "code";
    public $incrementing = false;

   // const NEW_ORDER = "NEW_ORDER";
    const UNPROCESSED = "UNPROCESSED"; // Non Traité
    const PAID = "PAID"; // Payé
    const UNDER_PROCESS = "UNDER_PROCESS"; // En Cours de Traitement
    const DELIVERED = "DELIVERED"; // Livré
    const REFUNDED_REQUEST = "REFUNDED_REQUEST"; // Remboursement Demandé
    const RETURNED_ORDER = "RETURNED"; // Retourné
    const REFUNDED_ORDER = "REFUNDED"; // Remboursé
    const CANCELED = "CANCELED"; // Annulé
    const REJECTED = "REJECTED"; // Rejété

    const CREATED = "CREATED"; // Crée
    const OPENED = "OPENED"; // Ouvert
    const ONGOING = "ONGOING"; // En Attente
    const COMPLETED = "COMPLETED";
    const STOPPED = "STOPPED";
    const PENDING = "PENDING"; // En Cours
    const FAILED = "FAILED"; // Echoué
    const APPROVED = "APPROVED"; // Approuvé

    const ACTIVE = "ACTIVE"; //
    const INACTIVE = "INACTIVE"; //
    const ENABLED = "ENABLED"; //
    const DISABLED = "DISABLED"; //

    protected $casts = [
        'style' => "array"
    ];

    public function getRouteKey(){
        return "code"; // TODO: Change the autogenerated stub
    }

    public function getNameAttribute($value){
        return __($value);
    }


    public function getBadgeDotAttribute(){
        return "<i class='badge-dot' style='background-color: $this->color !important;'></i> $this->name";
    }


    public function getBadgeLabelAttribute(){
        $status = $this;
        $style = (is_array($status->style))
                    ? json_encode($status->style['label']) ?? ""
                    : $status->style ?? "";

        $style = str_replace("{","",$style);
        $style = str_replace("}","",$style);
        $style = str_replace('"',"",$style);
        $style = str_replace(',',"",$style);

        return "<label class='badge' style='$style'><span>$status->name</span></label>";
    }

}
