<?php

namespace App\Services\Equipment\Part;

use App\Entities\Equipment\Part\IpEntity;
use App\Entities\Equipment\Part\LineEntity;
use App\Models\Equipment\Part\IpModel;
use CodeIgniter\HTTP\IncomingRequest;

class IpService extends PartService
{
    protected ?IncomingRequest $request = null;
    public function __construct(?IncomingRequest $request = null)
    {
        parent::__construct($request);
        $this->addClassName('Ip');
    }
    public function getModelClass(): IpModel
    {
        return new IpModel();
    }
    public function getEntityClass(): IpEntity
    {
        return new IpEntity();
    }
    public function getFormFields(): array
    {
        return [
            "lineinfo_uid",
            "ip",
            "status",
        ];
    }
    public function getFilterFields(): array
    {
        return ["lineinfo_uid", 'status'];
    }
    public function getBatchJobFields(): array
    {
        return ['status'];
    }
    public function getIndexFields(): array
    {
        return ['lineinfo_uid', 'ip', 'status'];
    }

    public function createByLineInfo(LineEntity $entity, string $ip): IpEntity
    {
        $formDatas                 = [];
        $formDatas['lineinfo_uid'] = $entity->getPK();
        $formDatas['ip']           = $ip;
        $formDatas['status']       = DEFAULTS['STATUS'];
        return $this->create($formDatas, new IpEntity());
    }
}
