<?php

namespace App\Models;

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

/**
 * @property integer id
 * @property string name
 * @property string created_at
 * @property string updated_at
 * @property string deleted_at
 *
 * @SWG\Definition(
 *      definition="Invoice",
 *      required={"lead_id", "website_id", "amount", "currency", "comments"},
 *      @SWG\Property(
 *          property="id",
 *          description="id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="lead_id",
 *          description="lead_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="user_id",
 *          description="user_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="website_id",
 *          description="website_id",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="amount",
 *          description="amount",
 *          type="integer",
 *          format="int32"
 *      ),
 *      @SWG\Property(
 *          property="currency",
 *          description="currency",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="comments",
 *          description="comments",
 *          type="string"
 *      ),
 *      @SWG\Property(
 *          property="created_at",
 *          description="created_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="updated_at",
 *          description="updated_at",
 *          type="string",
 *          format="date-time"
 *      ),
 *      @SWG\Property(
 *          property="deleted_at",
 *          description="deleted_at",
 *          type="string",
 *          format="date-time"
 *      )
 * )
 */
class Invoice extends Model
{
    use SoftDeletes;

    public $table = 'invoices';


    protected $dates = ['deleted_at'];


    public $fillable = [
        'lead_id',
        'user_id',
        'website_id',
        'amount',
        'currency',
        'comments',
        'status',
        'team_id'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'id'         => 'integer',
        'lead_id'    => 'integer',
        'user_id'    => 'integer',
        'website_id' => 'integer',
        'amount'     => 'integer',
        'currency'   => 'string',
        'comments'   => 'string',
        'status'     => 'string',
        'team_id'    => 'integer'
    ];

    /**
     * The objects that should be append to toArray.
     *
     * @var array
     */
    protected $with = [
        'leads',
        'websites',
        'user'
    ];

    /**
     * The attributes that should be append to toArray.
     *
     * @var array
     */
    protected $appends = [];

    /**
     * The attributes that should be visible in toArray.
     *
     * @var array
     */
    protected $visible = [];

    /**
     * Validation create rules
     *
     * @var array
     */
    public static $rules = [
        'lead_id'    => 'required',
        'website_id' => 'required',
        'amount'     => 'required',
        'currency'   => 'required',
        'comments'   => 'sometimes',
        'team_id'    => 'required',
    ];

    /**
     * Validation update rules
     *
     * @var array
     */
    public static $update_rules = [
        'lead_id'    => 'required',
        'website_id' => 'required',
        'amount'     => 'required',
        'currency'   => 'required',
        'comments'   => 'sometimes',
        'team_id'    => 'required',
    ];

    /**
     * Validation api rules
     *
     * @var array
     */
    public static $api_rules = [
        'lead_id'    => 'required',
        'website_id' => 'required',
        'amount'     => 'required',
        'currency'   => 'required',
        'comments'   => 'required'
    ];

    /**
     * Validation api update rules
     *
     * @var array
     */
    public static $api_update_rules = [
        'lead_id'    => 'required',
        'website_id' => 'required',
        'amount'     => 'required',
        'currency'   => 'required',
        'comments'   => 'required'
    ];

    public function leads()
    {
        return $this->belongsTo(Lead::class, 'lead_id', 'id');
    }

    public function websites()
    {
        return $this->belongsTo(Website::class, 'website_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

}
