<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\SoftDeletes;

class Marketer extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'name',
        'email',
        'phone',
        'website',
        'code',
        'token',
        'commission',
        'discount',
    ];


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

    /**
     * Return User
     * @return HasOneThrough
     */
    public function user() :HasOneThrough
    {
        return $this->hasOneThrough(User::class, UserMarketer::class, 'marketer_id', 'id', 'id', 'user_id')->where('role', 'marketer');
    }

    // /**
    //  * Return stores
    //  * @return BelongsTo
    //  */
    // public function stores() :HasManyThrough
    // {
    //     return $this->hasManyThrough(Store::class, Order::class);
    // }

    // /**
    //  * Return Domains
    //  * @return BelongsTo
    //  */
    // public function domains() :HasManyThrough
    // {
    //     return $this->hasManyThrough(Domain::class, Order::class);
    // }

    // /**
    //  * Return Orders
    //  * @return BelongsTo
    //  */
    // public function orders() :HasMany
    // {
    //     return $this->hasMany(Order::class);
    // }

}
