from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class Album(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    artist = db.Column(db.String(100), nullable=False)
    year = db.Column(db.Integer, nullable=False)
    cover_image = db.Column(db.String(100), nullable=True)
    songs = db.relationship('Song', backref='album', lazy=True)

    def __repr__(self):
        return f'<Album {self.name} by {self.artist}>'

class Song(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    author = db.Column(db.String(100), nullable=False)
    album_id = db.Column(db.Integer, db.ForeignKey('album.id'), nullable=False)
    lyrics = db.Column(db.Text, nullable=False)
    pista = db.Column(db.Integer, nullable=False)


    def __repr__(self):
        return f'<Song {self.title}>'
