<?php

namespace App\Models;

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

class Seat extends Model
{
    protected $fillable = [
        'name_bn',
        'name_en',
        'seat_code',
        'seat_type',

        'division_id',
        'district_id',
        'upazila_id',
        'city_id',

        'status',

        'male_voters',
        'female_voters',
        'other_voters',
        'total_voters',

        'description',
    ];

    protected $casts = [
        'male_voters' => 'integer',
        'female_voters' => 'integer',
        'other_voters' => 'integer',
        'total_voters' => 'integer',
    ];

    // Candidate relation (your existing candidates table has seat_id)
    public function candidates(): HasMany
    {
        return $this->hasMany(Candidate::class);
    }

    // Optional geo relations (if you created these tables/models)
    public function division(): BelongsTo
    {
        return $this->belongsTo(Division::class);
    }

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

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

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

    // Pivot relation (for seat ↔ ward mapping later)
    // requires pivot table seat_ward (we will do later)
    public function wards(): BelongsToMany
    {
        return $this->belongsToMany(Ward::class, 'seat_ward')
            ->withTimestamps();
    }

    // Voter areas (later table voter_areas)
    public function voterAreas(): HasMany
    {
        return $this->hasMany(VoterArea::class);
    }
    
    
}
