/*
  # Create servers table for Proxmox Dashboard

  1. New Tables
    - `servers`
      - `id` (uuid, primary key)
      - `name` (text, server name)
      - `model` (text, server model like Dell R730)
      - `cpu_model` (text, CPU model name)
      - `ram_gb` (integer, RAM amount in GB)
      - `influx_org` (text, InfluxDB organization)
      - `influx_token` (text, InfluxDB API token)
      - `influx_url` (text, InfluxDB server URL)
      - `created_at` (timestamp with timezone)

  2. Security
    - Enable RLS on `servers` table
    - Add policies for authenticated users to manage their servers
*/

CREATE TABLE servers (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  name text NOT NULL,
  model text NOT NULL,
  cpu_model text NOT NULL,
  ram_gb integer NOT NULL,
  influx_org text NOT NULL,
  influx_token text NOT NULL,
  influx_url text NOT NULL,
  created_at timestamptz DEFAULT now()
);

-- Enable Row Level Security
ALTER TABLE servers ENABLE ROW LEVEL SECURITY;

-- Create policies
CREATE POLICY "Users can view their servers"
  ON servers
  FOR SELECT
  TO authenticated
  USING (true);

CREATE POLICY "Users can insert their servers"
  ON servers
  FOR INSERT
  TO authenticated
  WITH CHECK (true);

CREATE POLICY "Users can update their servers"
  ON servers
  FOR UPDATE
  TO authenticated
  USING (true);

CREATE POLICY "Users can delete their servers"
  ON servers
  FOR DELETE
  TO authenticated
  USING (true);