from __future__ import annotations

from PIL import Image 
import os

from path import Path

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from page import Page 
    from album import Album

class Picture():
    def __init__(self, picture_path: Path, page = None, raw: Path|None = None, albums: list[Album] = [], is_repertoried: bool = True):
        self._large: Path = picture_path
        self._small: Path = Path(picture_path.get_absolute_path()[:-4] + "_small.jpg")
        self._export_file: Path = Path(picture_path.get_absolute_path() + ".out.pp3")
        self._raw: Path|None = raw
        self._page: Page = page
        self._albums: list[Album] = albums
        self._is_reperoried: bool = is_repertoried

    def get_small(self):
        if not self._small.exist():
            self.gen_small()
        return self._small
    
    def get_large(self):
        return self._large
    
    def get_export_file(self):
        return self._export_file

    def gen_small(self):
        im = Image.open(self.large.get_absolute_path()).convert("RGB")
        im.save(self._small.get_absolute_path(), quality=95, optimize=True)

        