<?php

declare(strict_types=1);

namespace App\Models;

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

class AcademyChallengeSubmission extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'challenge_id',
        'user_id',
        'artwork_id',
        'prompt_used',
        'workflow_notes',
        'ai_tool_used',
        'is_ai_generated',
        'is_ai_assisted',
        'moderation_status',
        'submitted_at',
    ];

    protected $casts = [
        'is_ai_generated' => 'boolean',
        'is_ai_assisted' => 'boolean',
        'submitted_at' => 'datetime',
    ];

    public function scopeApproved(Builder $query): Builder
    {
        return $query->where('moderation_status', 'approved');
    }

    public function challenge(): BelongsTo
    {
        return $this->belongsTo(AcademyChallenge::class, 'challenge_id');
    }

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

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