<?php
namespace shop;

class ProductSet implements \ArrayAccess
{
  public function offsetExists($offset) {
    return isset($this->$offset);
  }

  public function offsetGet($offset) {
    return $this->$offset;
  }

  public function offsetSet($offset , $value) {
    $this->$offset = $value;
  }

  public function offsetUnset($offset) {
    unset($this->$offset);
  }

  public function __construct( int $set_id )
  {
    global $mdb;

    $repo = new \Domain\ProductSet\ProductSetRepository( $mdb );
    $data = $repo->find( $set_id );

    foreach ( $data as $key => $val )
      $this->$key = $val;
  }

  //lista dostepnych kompletow (fasada do repozytorium)
  static public function sets_list()
  {
    global $mdb;
    $repo = new \Domain\ProductSet\ProductSetRepository( $mdb );
    return $repo->allSets();
  }

  // usuwanie kompletu produktow (fasada do repozytorium)
  static public function set_delete( int $set_id )
  {
    global $mdb;
    $repo = new \Domain\ProductSet\ProductSetRepository( $mdb );
    return $repo->delete( $set_id );
  }
}
