from app.brm.brn import BRN
from app.extensions import db
from app.models import AbstractConfiguration, AbstractResource


class Onion(AbstractConfiguration):
    group_id = db.Column(db.Integer(), db.ForeignKey("group.id"), nullable=False)
    domain_name = db.Column(db.String(255), nullable=False)
    onion_name = db.Column(db.String(56), nullable=False, unique=True)

    group = db.relationship("Group", back_populates="onions")


class Eotk(AbstractResource):
    group_id = db.Column(db.Integer(), db.ForeignKey("group.id"), nullable=False)
    instance_id = db.Column(db.String(100), nullable=True)
    provider = db.Column(db.String(20), nullable=False)
    region = db.Column(db.String(20), nullable=False)

    group = db.relationship("Group", back_populates="eotks")

    @property
    def brn(self) -> BRN:
        return BRN(
            group_id=self.group_id,
            provider=self.provider,
            product="eotk",
            resource_type="instance",
            resource_id=self.region
        )
