<?php

declare(strict_types=1);

namespace App\Models;

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

final class ArtworkRelation extends Model
{
    use HasFactory;

    public const TYPE_REMAKE_OF = 'remake_of';
    public const TYPE_REMASTER_OF = 'remaster_of';
    public const TYPE_REVISION_OF = 'revision_of';
    public const TYPE_INSPIRED_BY = 'inspired_by';
    public const TYPE_VARIATION_OF = 'variation_of';

    protected $fillable = [
        'source_artwork_id',
        'target_artwork_id',
        'relation_type',
        'note',
        'sort_order',
        'created_by_user_id',
    ];

    protected $casts = [
        'sort_order' => 'integer',
    ];

    public function sourceArtwork(): BelongsTo
    {
        return $this->belongsTo(Artwork::class, 'source_artwork_id');
    }

    public function targetArtwork(): BelongsTo
    {
        return $this->belongsTo(Artwork::class, 'target_artwork_id');
    }

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by_user_id');
    }
}