from dataclasses import dataclass

from abra_python.resources.base import BaseResource


class ConstantSymbol(BaseResource):
    def list(self, take: int = 10):
        response = self.requestor.request(
            method='GET',
            endpoint_url='/constantsymbols',
            query={'take': take}
        )

        return [
            self.Data(item)
            for item in response
        ]

    def get(self, constant_symbol_id: str):
        response = self.requestor.request(
            method='GET',
            endpoint_url=f'/constantsymbols/{constant_symbol_id}'
        )

        return self.Data(response)

    def create(self, payload: dict):
        response = self.requestor.request(
            method='POST',
            endpoint_url='/constantsymbols',
            payload=payload
        )

        return self.Data(response)

    def update(self, constant_symbol_id: str, payload: dict):
        response = self.requestor.request(
            method='PUT',
            endpoint_url=f'/constantsymbols/{constant_symbol_id}',
            payload=payload
        )

        return self.Data(response)

    @dataclass
    class Data:
        code: int
        hidden: bool
        id: str
        isforeign: bool
        name: str
        objversion: int

        def __init__(self, data: dict):
            self.code = data.get("code")
            self.hidden = data.get("hidden")
            self.id = data.get("id")
            self.isforeign = data.get("isforeign")
            self.name = data.get("name")
            self.objversion = data.get("objversion")
