export class GPIOError extends Error {
  code: string

  constructor(message: string, code: string) {
    super(message)
    this.name = "GPIOError"
    this.code = code
  }
}

export class PermissionError extends GPIOError {
  constructor(path: string) {
    super(
      `Permission denied accessing ${path}. Try:\n` +
        `  1. Add your user to the 'gpio' group: sudo usermod -aG gpio $USER\n` +
        `  2. Log out and back in\n` +
        `  3. Or run with sudo (not recommended for production)`,
      "PERMISSION_DENIED"
    )
    this.name = "PermissionError"
  }
}

export class PinInUseError extends GPIOError {
  constructor(pin: number) {
    super(
      `Pin ${pin} is already in use by another process or request. ` +
        `Only one process can control a GPIO pin at a time.`,
      "PIN_IN_USE"
    )
    this.name = "PinInUseError"
  }
}

export class ChipNotFoundError extends GPIOError {
  constructor(path: string) {
    super(
      `GPIO chip not found at ${path}. Check that:\n` +
        `  1. The path exists (ls ${path})\n` +
        `  2. GPIO hardware is enabled in your system configuration\n` +
        `  3. You're running on compatible hardware (Raspberry Pi, etc.)`,
      "CHIP_NOT_FOUND"
    )
    this.name = "ChipNotFoundError"
  }
}

export class InvalidConfigError extends GPIOError {
  constructor(message: string) {
    super(message, "INVALID_CONFIG")
    this.name = "InvalidConfigError"
  }
}
