<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Curtain extends Model
{
    protected $guarded = [];
    public $timestamps = false;
    protected $casts = [
        'tailor_finished_at' => 'datetime',
        'accepted_at' => 'datetime',
    ];

    public function tailoringProduct()
    {
        return $this->hasOne(TailoringProduct::class);
    }

    public function tailor()
    {
        return $this->belongsTo(Tailor::class);
    }

    public function windowDetails()
    {
        return $this->hasMany(CurtainWindowDetail::class);
    }

    public function doorDetails()
    {
        return $this->hasMany(CurtainDoorDetail::class);
    }

    public function beddingDetails()
    {
        return $this->hasMany(CurtainBeddingDetail::class);
    }

    public function mattressDetails()
    {
        return $this->hasMany(CurtainBeddingDetail::class)->where('type', 'mattress');
    }

    public function pillowDetails()
    {
        return $this->hasMany(CurtainBeddingDetail::class)->where('type', 'pillow');
    }

    public function bolsterDetails()
    {
        return $this->hasMany(CurtainBeddingDetail::class)->where('type', 'bolster');
    }

    public function reorders()
    {
        return $this->hasMany(CurtainReorder::class)->orderByDesc('reordered_at');
    }

    public function latestReorder()
    {
        return $this->hasOne(CurtainReorder::class)->latest('reordered_at');
    }
}
