<?php
class ProductionSite { private $pdo; public function __construct(){ $this->pdo=$GLOBALS['pdo']; }
  public function all(){ return $this->pdo->query("SELECT * FROM production_sites WHERE is_active=1 ORDER BY sort_order ASC, name ASC")->fetchAll(); }
  public function allWithInactive(){ return $this->pdo->query("SELECT * FROM production_sites ORDER BY sort_order ASC, name ASC")->fetchAll(); }
  public function find($id){ $st=$this->pdo->prepare("SELECT * FROM production_sites WHERE id=?"); $st->execute([$id]); return $st->fetch(); }
  public function create($d){ $st=$this->pdo->prepare("INSERT INTO production_sites (code,name,description,sort_order,is_active) VALUES (?,?,?,?,?)"); return $st->execute([$d['code'],$d['name'],$d['description']??'', $d['sort_order']??0,$d['is_active']??1]); }
  public function update($id,$d){ $st=$this->pdo->prepare("UPDATE production_sites SET code=?, name=?, description=?, sort_order=?, is_active=? WHERE id=?"); return $st->execute([$d['code'],$d['name'],$d['description']??'', $d['sort_order']??0,$d['is_active']??1,$id]); }
  public function delete($id){ $st=$this->pdo->prepare("DELETE FROM production_sites WHERE id=?"); return $st->execute([$id]); }
}

