<?php

namespace EasyRestaurantManager\Models;

class Color extends Model
{
    protected $model = 'erm_color_settings';

    public static function store($color)
    {
        global $wpdb;
        $wpdb->insert($wpdb->prefix . 'erm_color_settings', $color);
        return $wpdb->insert_id;
    }

    public static function updateColor($color)
    {
        global $wpdb;
        if (!isset($color['id'])) {
            return ('missing id');
        }
        $id = (int) $color['id']; 
        unset($color['id']); 

        $updated = $wpdb->update($wpdb->prefix . 'erm_color_settings',$color, ['id' => $id],null, ['%d']
        );

        if ($updated === false) {
            return ('update failed');
        }
        return $updated;
    }

    public static function getColor(){
        global $wpdb;
        $res = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}erm_color_settings  ORDER BY id DESC");
        return $res;
    }

    public static function deleteColor($id){
        global $wpdb;
        $res = $wpdb->delete($wpdb->prefix . 'erm_color_settings', ['id' => $id]);
        return $res;
    }
}
