[{
	"resource": "/c:/Users/alexa/Desktop/SAE-PHP/classes/models/Album.php",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "P1005",
	"severity": 8,
	"message": "Expected 6 arguments. Found 5.",
	"source": "intelephense",
	"startLineNumber": 18,
	"startColumn": 28,
	"endLineNumber": 18,
	"endColumn": 80
}][{
	"resource": "/C:/Users/alexa/Desktop/SAE-PHP/classes/models/db/AlbumDB.php",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "P1006",
	"severity": 8,
	"message": "Expected type 'string'. Found 'models\\Artiste'.",
	"source": "intelephense",
	"startLineNumber": 29,
	"startColumn": 69,
	"endLineNumber": 29,
	"endColumn": 77
}][{
	"resource": "/C:/Users/alexa/Desktop/SAE-PHP/classes/models/db/AlbumDB.php",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "P1006",
	"severity": 8,
	"message": "Expected type 'models\\Artiste'. Found 'array'.",
	"source": "intelephense",
	"startLineNumber": 29,
	"startColumn": 79,
	"endLineNumber": 29,
	"endColumn": 81
}][{
	"resource": "/C:/Users/alexa/Desktop/SAE-PHP/classes/models/db/AlbumDB.php",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "P1014",
	"severity": 8,
	"message": "Undefined property '$musiques'.",
	"source": "intelephense",
	"startLineNumber": 33,
	"startColumn": 25,
	"endLineNumber": 33,
	"endColumn": 33
}]<?php

namespace models\db;

class CollectionMusicale {
    protected int $id;
    protected string $titre;
    protected $auteur; // Artiste pour Album, auteurPlaylist pour Playlist
    protected ?string $image;
    protected array $musiques = [];
    protected string $anneePublication;

    public function __construct(int $id, string $titre, $auteur, array $musiques = [], string $images, string $anneePublication) {
        $this->id = $id;
        $this->titre = $titre;
        $this->musiques = $musiques;
        $this->auteur = $auteur;
        $this->image = $images;
        $this->anneePublication = $anneePublication;
    }

    public function getId(): int {
        return $this->id;
    }

    public function getTitre(): string {
        return $this->titre;
    }

    public function getMusiques(): array {
        return $this->musiques;
    }

    public function getAuteur() {
        return $this->auteur;
    }

    public function setId(int $id): void {
        $this->id = $id;
    }

    public function setTitre(string $titre): void {
        $this->titre = $titre;
    }

    public function setMusiques(array $musiques): void {
        $this->musiques = $musiques;
    }

    public function setAuteur($auteur): void {
        $this->auteur = $auteur;
    }

    public function getImage(): string {
      return $this->image;
    }

    public function getAnnee() : string{
      return $this->anneePublication;
    }
}<?php

namespace models\db;

use models\Album;
use models\Artiste;
use models\Musique;

class AlbumDB {
    public static function addAlbum(Album $album): bool {
        $db = Database::getInstance();
        $stmt = $db->prepare("INSERT INTO album(titreAlbum, anneeAlbum, imgAlbum) VALUES (:titre, :annee, :imageAl)");
        $titreAlbum = $album->getTitre();
        $stmt->bindParam(":titre", $titreAlbum);
        $annee = $album->getAnnee();
        $stmt->bindParam(":annee", $annee);
        $imgAlbum = $album->getImage();
        $stmt->bindParam(":imageAl", $imgAlbum);
        return $stmt->execute();
    }

    public static function getAlbum(int $id): ?Album {
        $db = Database::getInstance();
        $result = $db->query("SELECT album.*, artiste.*, musique.* FROM album JOIN artiste ON album.idA = artiste.idA LEFT JOIN musique ON musique.idAlbum = album.idAlbum WHERE album.idAlbum = $id");
        $album = null;
        foreach ($result as $r) {
            if (!$album) {
                $artiste = new Artiste($r["idA"], $r["nomA"]);
                $album = new Album($r["idAlbum"], $r["titreAlbum"], $artiste, [], $r["imgAlbum"], $r["anneeAlbum"]);
            }

            if ($r["idM"]) {
                $album->musiques[] = new Musique($r["idM"], $r["nomM"],"lien");
            }
        }

        return $album;
    }

    public static function getInfosCardsAlbum(string $category): array {
        $db = Database::getInstance();
        $conditions = '';
        switch ($category) {
            case 'recents':
                $conditions = 'ORDER BY album.anneeAlbum DESC';
                break;
            case 'populaires':
                // a faire quand on aura le nb d'écoute
                break;
            default:
                $conditions = "ORDER BY album.idAlbum DESC";
                break;
        }

        $stmt = $db->query("SELECT album.*, artiste.*, musique.* FROM album JOIN artiste ON album.idA = artiste.idA LEFT JOIN musique ON musique.idAlbum = album.idAlbum $conditions");
        $albums = [];

        foreach ($stmt as $s) {
            $idAlbum = $s["idAlbum"];
            if (!isset($albums[$idAlbum])) {
                $artiste = new Artiste($s["idA"], $s["nomA"]);
                $album = new Album($s["idAlbum"], $s["titreAlbum"], $artiste, [], $s["imgAlbum"], $s["anneeAlbum"]);
                $albums[$idAlbum] = $album;
            }

            if ($s["idM"]) {
                $albums[$idAlbum]->musiques[] = new Musique($s["idM"], $s["nomM"], "lien");
            }
        }

        return array_values($albums);
    }
}<?php

namespace models;

use models\db\CollectionMusicale;

class Playlist extends CollectionMusicale {
    private string $descriptionP;
    private int $idU;
    private string $dateMAJ;

    public function __construct(
        int $id,
        string $nomP,
        string $auteurPlaylist,
        string $descriptionP,
        int $idU,
        array $musiques = [],
        ?string $imgPlaylist = null
    ) {
        parent::__construct($id, $nomP, $auteurPlaylist, $musiques, $imgPlaylist);
        $this->descriptionP = $descriptionP;
        $this->idU = $idU;
    }

    public function getDescriptionP(): string {
        return $this->descriptionP;
    }

    public function getIdU(): int {
        return $this->idU;
    }
}