<?php

namespace App\Models;

use Config\Database;
use PDO;

class AreaGroupType extends BaseModel
{
    protected static $table = 'area_group_types';

    public $id;
    public $area_id;
    public $group_type_id;
    public $active;
    public $deleted_at;

    public function __construct($data = [])
    {
        parent::__construct($data);
        $this->active = $data['active'] ?? 1;
    }

    public function getArea()
    {
        return Area::find($this->area_id);
    }

    public function getGroupType()
    {
        return GroupType::find($this->group_type_id);
    }

    public function getGroups()
    {
        $db = Database::getConnection();
        $query = "SELECT * FROM groups WHERE area_group_type_id = :id";
        $stmt = $db->prepare($query);
        $stmt->execute([':id' => $this->id]);
        return $stmt->fetchAll(PDO::FETCH_OBJ);
    }
}
