var icalToolkit = require('../lib/main');

var builder = icalToolkit.createIcsFileBuilder();

/*
 * Settings (All Default values below)
 * */
builder.spacers = true; //Add space in ICS file, better reading
builder.NEWLINE_CHAR = '\r\n'; //Newline char to use
builder.throwError = false; //If true throws errors, else returns error
builder.ignoreTZIDMismatch = true; //If TZID is invalid, ignore or not to ignore!


/**
 * Build ICS
 * */
builder.calname = 'Yo Cal';
builder.timezone = 'asia/kalcutta';
builder.tzid = 'america/new_york';

builder.method = 'REQUEST';

builder.events.push({
  //Required: type Date()
  start: new Date(),
  //Required: type Date()
  end: new Date(),
  //transp
  transp: 'OPAQUE',
  //Required: type String
  summary: 'Test Event',

  //All Optionals Below
  alarms: [15, 10, 5], //Alarms, array in minutes
  additionalTags: {
    'SOMETAG': 'SOME VALUE'
  }, //Optional
  uid: null, //Optional, default autogenerated
  sequence: null, //The sequence number in update, Default: 0
  repeating: {
    freq: 'DAILY',
    count: 10,
    interval: 10,
    until: new Date()
  },
  allDay: true,
  stamp: new Date(),
  floating: false,
  location: 'Home',
  description: 'Testing it!',
  organizer: {
    name: 'Kushal Likhi',
    email: 'test@mail',
    sentBy: 'hello@test.com'
  },
  attendees: [
    {
      name: 'A1', //Required
      email: 'a1@email.com', //Required
      status: 'TENTATIVE', //Optional
      role: 'REQ-PARTICIPANT', //Optional
      rsvp: true //Optional
    },
    {
      name: 'A2',
      email: 'a2@email.com'
    }
  ],
  method: 'PUBLISH',
  status: 'CONFIRMED',
  url: 'http://google.com'
});

builder.additionalTags = {
  'SOMETAG': 'SOME VALUE'
};

var icsFileContent = builder.toString();

if (icsFileContent instanceof Error) {
  console.log('Returned Error, you can also configure to throw errors!');
  //handle error
}

console.log(icsFileContent);
