-- Add direct_claim_id to lost_items table
ALTER TABLE lost_items 
ADD COLUMN direct_claim_id INT UNSIGNED NULL,
ADD CONSTRAINT fk_lost_items_direct_claim 
  FOREIGN KEY (direct_claim_id) REFERENCES claims(id) 
  ON DELETE SET NULL;

-- Add new claim status
ALTER TABLE claims 
MODIFY COLUMN status VARCHAR(50) DEFAULT 'pending';

-- Add index for better performance
CREATE INDEX idx_lost_items_direct_claim ON lost_items(direct_claim_id);
CREATE INDEX idx_lost_items_status ON lost_items(status);
CREATE INDEX idx_claims_status ON claims(status);

-- Add direct_claim_id to lost_items table
ALTER TABLE lost_items 
  ADD COLUMN IF NOT EXISTS direct_claim_id INT UNSIGNED NULL,
  ADD CONSTRAINT fk_lost_items_direct_claim 
    FOREIGN KEY (direct_claim_id) REFERENCES claims(id) 
    ON DELETE SET NULL;

-- Add new claim status
ALTER TABLE claims 
  MODIFY COLUMN status VARCHAR(50) DEFAULT 'pending';

-- Add indexes (only if they don't exist)
CREATE INDEX IF NOT EXISTS idx_lost_items_direct_claim ON lost_items(direct_claim_id);
CREATE INDEX IF NOT EXISTS idx_lost_items_status ON lost_items(status);
CREATE INDEX IF NOT EXISTS idx_claims_status ON claims(status);

ALTER TABLE lost_items 
  ADD COLUMN direct_claim_id INT UNSIGNED NULL;

-- Add foreign key constraint
ALTER TABLE lost_items
  ADD CONSTRAINT fk_lost_items_direct_claim 
    FOREIGN KEY (direct_claim_id) REFERENCES claims(id) 
    ON DELETE SET NULL;

-- Modify claim status column
ALTER TABLE claims 
  MODIFY COLUMN status VARCHAR(50) DEFAULT 'pending';

-- Create index for direct_claim_id (new index, shouldn't exist)
CREATE INDEX idx_lost_items_direct_claim ON lost_items(direct_claim_id);

-- 1. Ubah kolom item_id agar boleh NULL
ALTER TABLE claims MODIFY item_id INT UNSIGNED NULL;

-- 2. Tambah kolom lost_item_id
ALTER TABLE claims 
ADD COLUMN lost_item_id INT UNSIGNED NULL AFTER item_id;

-- 3. Tambah Foreign Key untuk lost_item_id
ALTER TABLE claims
ADD CONSTRAINT fk_claims_lost_item
FOREIGN KEY (lost_item_id) REFERENCES lost_items(id)
ON DELETE SET NULL;