<?php

namespace App\Models;

use App\Models\CalendarMeta;
use Illuminate\Database\Eloquent\Model;

class Subscription extends Model
{
    protected $table = 'calendarsubscriptions';
    public $timestamps = false;

    protected $fillable = [
        'uri',
        'principaluri',
        'source',
        'displayname',
        'calendarcolor',
        'refreshrate',
        'calendarorder',
        'striptodos',
        'stripalarms',
        'stripattachments',

        // sync fields
        'last_sync_status',
        'last_sync_error',
        'last_sync_at',
        'lastmodified',
    ];

    protected $casts = [
        'striptodos'       => 'bool',
        'stripalarms'      => 'bool',
        'stripattachments' => 'bool',

        // sync fields
        'last_sync_at'     => 'datetime',
    ];

    public function meta()
    {
        return $this->hasOne(CalendarMeta::class, 'subscription_id');
    }
}
