<?php

declare(strict_types=1);

namespace Database\Seeders\Support;

use App\Models\Expert;
use App\Models\Producer;
use App\Models\Project;
use App\Models\User;
use Mortezaa97\Regions\Models\County;
use Mortezaa97\Regions\Models\Province;

final class DemoSeederContext
{
    public const DEMO_PASSWORD = '123456789';

    public static function admin(): ?User
    {
        return User::role('admin')->first();
    }

    public static function employer(): ?User
    {
        return User::query()->where('email', 'morteza@mori.com')->first()
            ?? User::role('employer')->first();
    }

    public static function producerUser(): ?User
    {
        return User::query()->where('email', 'producer@rievo.ir')->first()
            ?? User::role('producer')->first();
    }

    public static function expertUser(): ?User
    {
        return User::query()->where('email', 'expert@rievo.ir')->first()
            ?? User::role('expert')->first();
    }

    public static function writer(): ?User
    {
        return User::query()->where('email', 'writer@rievo.ir')->first();
    }

    public static function producer(): ?Producer
    {
        return Producer::query()->orderBy('id')->first();
    }

    public static function expert(): ?Expert
    {
        return Expert::query()->orderBy('id')->first();
    }

    public static function mainProject(): ?Project
    {
        return Project::query()->where('status', Project::STATUS_ACTIVE)->orderBy('id')->first();
    }

    public static function secondProject(): ?Project
    {
        return Project::query()->where('status', Project::STATUS_ACTIVE)->orderByDesc('id')->first();
    }

    public static function province(): ?Province
    {
        return Province::query()->first();
    }

    public static function county(?Province $province = null): ?County
    {
        $province ??= self::province();

        return $province
            ? County::query()->where('province_id', $province->id)->first()
            : County::query()->first();
    }
}
