///
/// class: Device.cs
///
///This file defines the abstract Device class, which serves as the base class for all device types (e.g., smartphones, smartwatches).
///It includes common properties and methods for managing device details and assignments.
///
/// Name: Rens Pastoor
/// Studentnumber: 555408
/// Date: 11 May 2025
///
///Version: 1
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PoloClubApp {
///
/// Abstract base class representing a device in the Polo Club system.
///
public abstract class Device {
///
/// Gets the unique identifier of the device.
///
public int Id { get; }
///
/// Gets the name of the device.
///
public string Name { get; }
///
/// Gets or sets the name of the player the device is assigned to.
///
public string PlayerName { get; set; }
///
/// Initializes a new instance of the Device class.
///
/// The unique identifier for the device.
/// The name of the device.
/// The name of the player the device is assigned to (optional).
protected Device(int id, string name, string playerName = null) {
Id = id;
Name = name;
PlayerName = playerName;
}
///
/// Gets detailed information about the device.
///
/// Formatted string with device details.
public abstract string GetDetails();
///
/// Checks if the device is currently assigned to a player.
///
/// True if assigned, false otherwise.
public bool IsAssigned(){
return !string.IsNullOrEmpty(PlayerName);
}
///
/// Assigns the device to a player.
///
/// Name of the player to assign to.
/// Water resistance for wearables (nullable).
/// Throws when assignment fails.
public void AssignDevice(string playerName, int? waterResistanceMeters){
if (IsAssigned()){
throw new Exception("Device is already assigned");
}
if (this is IWearable && waterResistanceMeters < 3){
throw new Exception("Water resistance must be 3 meters or more for wearables");
}
if (Id == 0){
throw new Exception("Invalid device ID");
}
PlayerName = playerName;
}
///
/// Returns the device from a player.
///
/// True if successful, false if device wasn't assigned.
public bool ReturnDevice(){
if (!IsAssigned()){
return false;
}
PlayerName = null;
return true;
}
}
}