<?php

namespace App\Models;

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

class Statistic extends Model
{
    //
    use SoftDeletes;

    const ELECTRIC = 1;
    const WATER = 2;
    const ROOM_PRICE = 3;
    const OTHER = 4;
    const DEPOSIT = 5;

    protected $fillable = [
        'money_info_id',
        'money_info_code',
        'collect_spend_id',
        'collect_spend_code',
        'amount',
        'sum',
        'type',
        'type_collect_spend',
        'hostel_id',
        'room_id',
        'owner_id',
        'month',
        'year',
        'reserve_id',
        'start_date',
        'end_date',
        'date_action',
        'created_at',
        'updated_at',
        'deleted_at'
    ];

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];

    public function getTypeCollectSpendTextAttribute()
    {
        $type = $this->attributes['type_collect_spend'];

        if ($type == CollectSpend::COLLECT) {
            return '<label class="label label-success">Thu</label>';
        } else if ($type == CollectSpend::SPEND) {
            return '<label class="label label-danger">Chi</label>';
        }

        return '<label class="label label-primary">Chưa rõ trạng thái</label>';
    }

    public function getTypeTextAttribute()
    {
        $type = $this->attributes['type'];
        if ($type == Statistic::ELECTRIC) {
            return '<label class="label label-success">Điện</label>';
        } else if ($type == Statistic::WATER) {
            return '<label class="label label-danger">Nước</label>';
        } else if ($type == Statistic::ROOM_PRICE) {
            return '<label class="label label-warning">Tiền phòng</label>';
        } else if ($type == Statistic::DEPOSIT) {
            return '<label class="label label-warning">Tiền coc</label>';
        } else if ($type == Statistic::OTHER) {
            return '<label class="label label-primary">Khác</label>';
        }
    }
}
