"""Location model."""

from shopdb.extensions import db
from .base import BaseModel


class Location(BaseModel):
    """Physical location model."""
    __tablename__ = 'locations'

    locationid = db.Column(db.Integer, primary_key=True)
    locationname = db.Column(db.String(100), unique=True, nullable=False)
    building = db.Column(db.String(100))
    floor = db.Column(db.String(50))
    room = db.Column(db.String(50))
    description = db.Column(db.Text)

    # Map configuration
    mapimage = db.Column(db.String(500), comment='Path to floor map image')
    mapwidth = db.Column(db.Integer)
    mapheight = db.Column(db.Integer)

    # Location-level position used as fallback when an asset has no own coords
    # and no inheritsposition relationship resolves. ADR-001 position resolution
    # chain priority 3.
    mapx = db.Column(db.Integer, comment='Default X coordinate for assets at this location')
    mapy = db.Column(db.Integer, comment='Default Y coordinate for assets at this location')

    def __repr__(self):
        return f"<Location {self.locationname}>"
