<?php

namespace classes;

class Part
{
    private float $varienceValue;
    private MysqliVeu $database;
    private array $partNumberDetails;
    private string $partNumber;

    public function __construct(string $partNumber, MysqliVeu $database)
    {
        $this->database = $database;
        $this->partNumber = $partNumber;

        $this->fetchPartNumberDetails();
    }

    private function fetchPartNumberDetails(): void
    {
        $sql = "SELECT
                part.*,
                e2part.item_cost,
                site.site_name
            FROM part 
                LEFT JOIN e2part ON part.part_number = e2part.part_number
                JOIN site ON site.id = part.site_id
            WHERE part.part_number = ?";

        $this->partNumberDetails = $this->database->queryParamsRow($sql, [$this->partNumber]);
    }

    public function getPartNumberDetails(): array
    {
        return $this->partNumberDetails;
    }
}
