<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Order extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'store_id',
        'marketer_id',
        'title',
        'name',
        'phone',
        'email',
        'meta',
    ];

    protected $casts = ['meta' => 'array'];

    /**
     * Return Logo of Store
     * @return string|null
     */
    public function getLogoAttribute() : ?string
    {
        return $this->meta ? ($this->meta['logo'] ?? null) : null;
    }

    /**
     * Return Commission of order
     * @return string|null
     */
    public function getCommissionAttribute() : ?string
    {
        return $this->meta ? ($this->meta['commission'] ?? null) : null;
    }

    /**
     * Return discount of order
     * @return string|null
     */
    public function getDiscountAttribute() : ?string
    {
        return $this->meta ? ($this->meta['discount'] ?? null) : null;
    }

    /**
     * Return price of order
     * @return string|null
     */
    public function getPriceAttribute() : ?string
    {
        return $this->meta ? ($this->meta['price'] ?? null) : null;
    }

    /**
     * Return total of order
     * @return string|null
     */
    public function getTotalAttribute() : ?string
    {
        return $this->meta ? ($this->meta['total'] ?? null) : null;
    }

    /**
     * Return Notes of Store
     * @return string|null
     */
    public function getNotesAttribute() : ?string
    {
        return $this->meta ? ($this->meta['notes'] ?? null) : null;
    }

    /**
     * Return Date of Store
     * @return string|null
     */
    public function getDateAttribute() : ?string
    {
        return Carbon::parse($this->updated_at)->format('F d Y');
    }

    // /**
    //  * Return store
    //  * @return BelongsTo
    //  */
    // public function store() :BelongsTo
    // {
    //     return $this->belongsTo(Store::class);
    // }

    /**
     * Return Marketer
     * @return BelongsTo
     */
    public function marketer() :BelongsTo
    {
        return $this->belongsTo(Marketer::class);
    }
}
