// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// ignore_for_file: public_member_api_docs, sort_constructors_first, 
// ignore_for_file: avoid_equals_and_hash_code_on_mutable_classes

import 'dart:convert';

class TodoModel {
  final int id;
  final int userId;
  final String title;
  final bool completed;
  TodoModel({
    required this.id,
    required this.userId,
    required this.title,
    required this.completed,
  });

  TodoModel copyWith({
    int? id,
    int? userId,
    String? title,
    bool? completed,
  }) =>
      TodoModel(
        id: id ?? this.id,
        userId: userId ?? this.userId,
        title: title ?? this.title,
        completed: completed ?? this.completed,
      );

  Map<String, dynamic> toMap() => <String, dynamic>{
        'id': id,
        'userId': userId,
        'title': title,
        'completed': completed,
      };

  factory TodoModel.fromMap(Map<String, dynamic> map) => TodoModel(
        id: map['id'] as int,
        userId: map['userId'] as int,
        title: map['title'] as String,
        completed: map['completed'] as bool,
      );

  String toJson() => json.encode(toMap());

  factory TodoModel.fromJson(String source) =>
      TodoModel.fromMap(json.decode(source) as Map<String, dynamic>);

  @override
  String toString() => 'TodoModel(id: $id, userId: $userId, title: '
      '$title, completed: $completed)';

  @override
  bool operator ==(covariant TodoModel other) {
    if (identical(this, other)) {
      return true;
    }

    return other.id == id &&
        other.userId == userId &&
        other.title == title &&
        other.completed == completed;
  }

  @override
  int get hashCode =>
      id.hashCode ^ userId.hashCode ^ title.hashCode ^ completed.hashCode;
}
