from __future__ import annotations

from jinja2 import Environment, FileSystemLoader

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from picture import Picture

from path import Path

env = Environment(loader=FileSystemLoader('src/templates'))
album_template = env.get_template('album.jinja')

class Album():

    def __init__(self, name: str, albums_path: Path,  pictures: list[Picture] = None, is_repertoried: bool = False):
        self._name: str = name
        self._pictures: list[Picture] = pictures or [] 
        self._is_repertoried: bool = is_repertoried
        self._path: Path = Path(albums_path, f"{name}.html")
    
    def add_picture(self, picture: Picture) -> None:
        self._pictures.append(picture)
    
    def _to_html(self) -> str|None:
        html_rendered = album_template.render(album=self)
        return html_rendered
    
    def create(self) -> Path:
        with open(self._path.get_absolute_path(), "w") as f:
            f.write(self._to_html())