<?php

namespace App\Models;

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

/**
 * @property int $id
 * @property int $ad_id
 * @property int $ads_placement_id
 * @property int $klik
 * @property string $tgl_update
 */
class AdsHistory extends Model
{
    protected $fillable = ['ad_id', 'ads_placement_id', 'klik', 'tgl_update'];

    protected function casts(): array
    {
        return [
            'klik' => 'integer',
            // Cast date:Y-m-d agar tersimpan 'YYYY-MM-DD' (bukan datetime) —
            // firstOrCreate updateOrCreate mencocokkan string tanggal polos.
            'tgl_update' => 'date:Y-m-d',
        ];
    }

    public function ad(): BelongsTo
    {
        return $this->belongsTo(Ad::class);
    }

    public function adsPlacement(): BelongsTo
    {
        return $this->belongsTo(AdsPlacement::class);
    }
}
